import React,{ useState, createContext ,useContext  }from 'react';

// 创建一个context
const CountContext = createContext();

function Context () {

    const [count, setCount] = useState(0)
    return (
        <div>
             <p>You clicked {count} times</p>
              <button onClick={() => setCount(count+1)}>
              click me!
              </button>
              <CountContext.Provider value={count}>
                  <Counter />
              </CountContext.Provider>
        </div>
    )
}


function Counter() {
    const count = useContext(CountContext);
    return (<h2>{count}</h2>)
}

export default Context

